const promisify = (api) => {
  return (options, ...params) => {
    return new Promise((resolve, reject) => {
      api(Object.assign({}, options, {
        success: resolve,
        fail(res) {
          console.error('request error ', res);
          reject(res);
        }
      }), ...params);
    }).catch(res => {
      console.log('Promise catch: ', res);
    });
  };
};

const complete = (api) => {
  return (options, ...params) => {
    return new Promise((resolve, reject) => {
      api(Object.assign({}, options, { complete: resolve }), ...params);
    }).catch(res => {
      console.log('Promise catch: ', res);
    });
  };
};

export { promisify, complete };
